/**
 * Copyright 2007 American Well Systems
 * All rights reserved.
 *
 * It is illegal to use, reproduce or distribute
 * any part of this Intellectual Property without
 * prior written authorization from American Well.
 */
package org.rich.charlesmurphy.model;

import org.ddevil.data.BeanData;
import org.ddevil.data.Internal;
import org.ddevil.data.set.BeanDataSet;
import org.ddevil.data.set.DataSet;

/**
 * @author Rich O'Connell
 *
 */
public class PageItem extends BeanData {
	private static final long serialVersionUID = 1522919568340496264L;

	private String pageName;
	private String method;
	private String pageTitle;

//	private ValueTracker sizeTracker;
//	private ValueTracker totalTracker;
//	private ValueTracker nonCachedTracker;
//	private ValueTracker cachedTracker;
//	private ValueTracker imageTracker;
//	private ValueTracker cssTracker;
//	private ValueTracker jsTracker;
//	private ValueTracker ajaxTracker;
//	private ValueTracker otherTracker;


	private double requestMax;

	public double getRequestMax() {
		return requestMax;
	}

	@Internal
	private DataSet<RequestGroup> groups;

	public DataSet<RequestGroup> getSamples() {
		return groups;
	}

	/**
	 * @param method
	 * @param pageName
	 */
	public PageItem(String pageName, String method) {
		this.method = method;
		this.pageName = pageName;
		this.pageTitle = "[" + (method.equals("POST") ? "PST" : method) + "] " + pageName;
		groups = new BeanDataSet<RequestGroup>();
//		sizeTracker = new ValueTracker();
//		totalTracker = new ValueTracker();
//		nonCachedTracker = new ValueTracker();
//		cachedTracker = new ValueTracker();
//		imageTracker= new ValueTracker();
//		cssTracker = new ValueTracker();
//		jsTracker = new ValueTracker();
//		ajaxTracker = new ValueTracker();
//		otherTracker = new ValueTracker();
	}

	public void addGroup(RequestGroup group) {
		groups.importRecord(group);
		if (group.getRequests() > requestMax) {
			requestMax = group.getRequests();
		}
//		sizeTracker.newValue(group.getTotalResponseSize());
//		totalTracker.newValue(group.getRequests());
//		nonCachedTracker.newValue(group.getSuccess());
//		cachedTracker.newValue(group.getCache());
//		imageTracker.newValue(group.getImages());
//		cssTracker.newValue(group.getCss());
//		jsTracker.newValue(group.getJs());
//		ajaxTracker.newValue(group.getAjax());
//		otherTracker.newValue(group.getOther());
	}

//	static class ValueTracker {
//		private int sampleSize = 0;
//		private long max = 0;
//		private long total = 0;
//		public void newValue(long n) {
//			sampleSize++;
//			total += n;
//			if (n > max) {
//				max = n;
//			}
//		}
//		public long getMax() {
//			return max;
//		}
//		public double getAverage() {
//			return sampleSize == 0 ? 0 : total / sampleSize;
//		}
//	}

//	public double getAjaxAverage() {
//		return ajaxTracker.getAverage();
//	}
//
//	public long getAjaxMax() {
//		return ajaxTracker.getMax();
//	}
//	public double getRequestAverage() {
//		return totalTracker.getAverage();
//	}
//
//	public long getRequestMax() {
//		return totalTracker.getMax();
//	}
//	public double getSizeAverage() {
//		return sizeTracker.getAverage();
//	}
//
//	public long getSizeMax() {
//		return sizeTracker.getMax();
//	}
//

	/**
	 * @return the pageName
	 */
	public String getPageName() {
		return pageName;
	}

	/**
	 * @param pageName the pageName to set
	 */
	public void setPageName(String pageName) {
		this.pageName = pageName;
	}

	/**
	 * @return the method
	 */
	public String getMethod() {
		return method;
	}

	/**
	 * @param method the method to set
	 */
	public PageItem setMethod(String method) {
		this.method = method;
		return this;
	}

	/**
	 * @param pageTitle the pageTitle to set
	 */
	public PageItem setPageTitle(String pageTitle) {
		this.pageTitle = pageTitle;
		return this;
	}

	/**
	 * @return the pageTitle
	 */
	public String getPageTitle() {
		return pageTitle;
	}

}
